import 'package:citiesocial/_include.dart';

///
///单个商品的组件，长方行的，但图片是方的，比如用到历史查看商品
///
class LongSquareGoodsItem extends StatelessWidget {
  final imageEdge;
  final GoodsEntity goods;

  ///是否是选择状态，给Offstage这个组件用的，false显示,true隐藏
  final bool offstage;
  final GestureTapCallback onTap;
  LongSquareGoodsItem(this.goods,
      {this.offstage = true, this.onTap, this.imageEdge = 150.0});

  void _goGoodsDetail(BuildContext context) {
    Navigator.push(
      context,
      MaterialPageRoute(
          builder: (BuildContext context) => GoodsDetail(
                goods,
              )),
    );
  }

  @override
  Widget build(BuildContext context) => Container(
        child: Column(
          children: <Widget>[
            GestureDetector(
              child: Row(
                children: <Widget>[
                  Offstage(
                    offstage: offstage,
                    child: Container(
                      child: Image.asset(
                        goods.selectedMyState
                            ? 'imgs/js_cells_img_selected.png'
                            : 'imgs/js_cells_img_not_selected.png',
                        width: 20.0,
                        height: 20.0,
                        fit: BoxFit.cover,
                      ),
                      padding: EdgeInsets.all(5.0),
                    ),
                  ),
                  Image(
                    image: CachedNetworkImageProvider(
                      '${goods.goods_img}',
                    ),
                    height: imageEdge,
                    width: imageEdge,
                    fit: BoxFit.cover,
                  ),
                  Expanded(
                    child: Container(
                      height: imageEdge,
                      color: Colors.white,
                      padding: EdgeInsets.symmetric(horizontal: 15.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text(
                            '${goods.goods_brand ?? goods.brand_name}',
                            style: TextStyle(
                              color: Colors.grey,
                              fontSize: 14.0,
                            ),
                            maxLines: 1,
                          ),
                          Text(
                            '${goods.goods_name}',
                            style: TextStyle(
                              color: Colors.black,
                              fontSize: 16.0,
                            ),
                            maxLines: 1,
                          ),
                          Text(
                            '${goods.price ?? goods.goods_price}',
                            style: TextStyle(
                              color: Colors.black54,
                              fontSize: 15.0,
                            ),
                            maxLines: 1,
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
              onTap: () => onTap == null ? _goGoodsDetail(context) : onTap(),
            ),
            Configs.dividerLine
          ],
        ),
        color: Colors.white,
      );
}
